window.onload = function() {
  var vm = new Vue({
    el: "#build-house",
    data: {
      buildImg: [],
      houseList: [],
      houseInfo: {},
      recommendList: []
    },
    created: function() {
      this.getImgUrl();
      this.getBuildImg();
      // this.getAllWait();
      // this.getHouseInfo();
      // this.getRecommend();
    },
    methods: {
      // 获取图片列表
      getBuildImg() {
        var _this = this;
        house_server.getBuildImg({ buildingId: "11000007862" }, function(data) {
          data.data.forEach(function(item) {
            _this.buildImg.push(item);
          });
          console.log(_this.buildImg);
        });
      },
      // 获取全部待租房源
      getAllWait: function() {
        var params = {
          buildingId: "1",
          new: "1",
          area: "1",
          price: "1",
          floor: "1",
          page: "1",
          size: "10"
        };
        house_server.getAllWait(params, function(data) {
          data.data.forEach(function(item) {
            vm.houseList.push(item);
          });
        });
      },
      // 获取楼盘信息
      getHouseInfo: function() {
        var _this = this;
        house_server.getHouseInfo({ buildingId: "1" }, function(data) {
          _this.houseInfo = Object.assign({}, _this.houseInfo, {
            buildingName: data.data.buildingName,
            tradingArea: data.data.tradingArea,
            townName: data.data.townName,
            latitude: data.data.latitude,
            longitude: data.data.longitude,
            building3dCode: data.data.building3dCode,
            buildingYear: data.data.buildingYear,
            totalArea: data.data.totalArea,
            tradingArea: data.data.tradingArea,
            totalNum: data.data.totalNum,
            loopName: data.data.loopName,
            developer: data.data.developer,
            totalFloors: data.data.totalFloors,
            address: data.data.address,
            elevatorNum: data.data.elevatorNum,
            overParking: data.data.overParking,
            underParking: data.data.underParking,
            airConditioning: data.data.airConditioning,
            inCompanys: data.data.inCompanys,
            managementCompany: data.data.managementCompany,
            managementFee: data.data.managementFee,
            featureService: data.data.featureService,
            buildingIntroduce: data.data.buildingIntroduce,
            isCommunity: data.data.isCommunity
          });
        });
      },
      //   获取楼盘周边推荐
      getRecommend() {
        var _this = this;
        house_server.getRecommend({ buildingId: "" }, function(data) {
          data.data.forEach(function(item) {
            _this.recommendList.push(item);
          });
        });
      },
      getImgUrl() {
        var ip = window.location.host,url = "";
        if (ip.indexOf("127.0.0.1") >= 0 || ip.indexOf("localhost") >= 0) {
          url = 'http://114.113.68.14:9000/image/';
        }else{
          url = "http://" + ip + "/image/";
        } 
        return url;
      }
    }
  });
};
